package com.example.xml.dao.impl;


import com.example.xml.dao.AccountDao;
import com.example.xml.pojo.Account;
import jakarta.annotation.Resource;
import org.springframework.jdbc.core.BeanPropertyRowMapper;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

/**
 * ClassName:AccountDaoImpl
 * Package:com.example.trans.dao.impl
 * Description:
 *
 * @Author:ZhangXin
 * @Create:2023/5/11-10:38
 * @Version:v1.0
 */
@Repository("accountDao")
public class AccountDaoImpl implements AccountDao {

    @Resource(name = "jdbcTemplate")
    private JdbcTemplate jdbcTemplate;

    @Override
    public Account selectByActon(String acton) {

        String sql = "select actno,balance from t_act where actno = ?";
        Account account = jdbcTemplate.queryForObject(sql, new BeanPropertyRowMapper<>(Account.class),acton);
        return account;
    }

    @Override
    public int update(Account act) {


        String sql = "update t_act set balance =? where actno =?";
        int count = jdbcTemplate.update(sql, act.getBalance(), act.getActno());
        return count;
    }

}
